package com.googlecode.continuity.core.server.mvc.validation;

import org.springframework.validation.Errors;
import com.googlecode.continuity.core.server.mvc.command.EditUserCommand;

/**
 * RegistrationValidator is used to check a registration request. In addition to the checks performed by the
 * {@link EditUserValidator} this class makes sure the
 * submitted passwords are valid and equal.
 *
 * @author Peter Schmitt <aragos@aragos.de>
 */
public class RegistrationValidator extends EditUserValidator {
  /**
   * Compares and validates both submitted passwords, writing errors if they aren't equal or invalid.
   *
   * @param command submitted command object
   * @param errors
   */
  public void checkPasswords(EditUserCommand command, Errors errors) {
    if (!command.getNewpass1().equals(command.getNewpass2())) {
      errors.rejectValue("newpass1", "error.password.noMatch");
      errors.rejectValue("newpass2", "error.password.noMatch");
    }
    
    validatePassword("newpass1", command.getNewpass1(), errors);
  }
}
